package com.broadengate.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;


import com.broadengate.model.Card;
import com.broadengate.service.CardService;

public class QueryAction extends DispatchAction{
	private CardService cardService;
	
	/******
	 * 用户查看自己卡的余额
	 * 核心功能由调用cardService对象的方法indCardByCardNO()实现
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward 对象
	 */
	public ActionForward query(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		System.out.println("QueryAction 进入");
		
		HttpSession session=request.getSession();
		String cardNO=request.getParameter("cardNO");
		
		Card card=cardService.findCardByCardNO(cardNO);
		String RMBBalance=card.getRmbbalance().toString();
		String dollarBalance=card.getDollarBalance().toString();
		String euroBalance=card.getEuroBalance().toString();
		
		session.setAttribute("rmbBalance",RMBBalance);
		session.setAttribute("dollarBalance",dollarBalance);
		session.setAttribute("euroBalance",euroBalance);
		
		return mapping.findForward("success");
			
	}
	public CardService getCardService() {
		return cardService;
	}
	public void setCardService(CardService cardService) {
		this.cardService = cardService;
	}
}
